package com.dream.inspect.modules.sys.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@Component
public class CORSInterceptor extends HandlerInterceptorAdapter {
	 @Override
	    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
	        //添加跨域CORS
		 response.setHeader("Access-control-Allow-Origin", request.getHeader("Origin"));
	        response.setHeader("Access-Control-Allow-Methods", request.getMethod());
	        response.setHeader("Access-Control-Allow-Credentials", "true");
	        response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"));
	        return true;
	    }
}
